﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.UI.Converters
{
    public class FxCopVersionConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var version = value as Version;
            if (version == null)
            {
                return "?";
            }

            switch (version.Major)
            {
                case 9:
                    return "1.36";
                case 10:
                    return "10.0";
                default:
                    return "?";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var version = value as string;
            if (version == null)
            {
                return new Version();
            }

            switch (version)
            {
                case "1.36":
                    return new Version(9, 0, 0, 0);
                case "10.0":
                    return new Version(10, 0, 0, 0);
                default:
                    return new Version();
            }
        }
    }
}
